<?php

namespace App\Jobs\Train;

use App\Models\Train\TrainSeatInfo\Repositories\Interfaces\TrainSeatInfoRepositoryInterface;
use App\Trip\Train\Seat\SeatInfo;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ProcessAddTrainSeatInfo implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private SeatInfo $seatDetail;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(SeatInfo $seatDetail)
    {
        $this->seatDetail = $seatDetail;
    }

    /**
     * Execute the job.
     *
     * @return void
     * @throws Exception
     */
    public function handle()
    {
        $trainSeatRepo = app(TrainSeatInfoRepositoryInterface::class);
        $trainSeatRepo->addTrainSeatInfo($this->seatDetail->toArray());
    }
}
